#include "gui/layers/MapLayer.h"
#include "gui/objects/GUIMap.h"
#include "gui/GUIMapFactory.h"

namespace gui {

MapLayer::MapLayer(SurfaceFactory* surfaceFactory, Map* map): Layer(), drawer(surfaceFactory) {
	// Se crea un Mapa grafico usando el Mapa del modelo
	gui::GUIMapFactory guiMapFactory;
	gui::GUIMap* guiMap = guiMapFactory.createGUIMap(&this->drawer, map);

	Portion portion;
	portion.x = guiMap->getXPos();
	portion.y = guiMap->getYPos();
	portion.w = guiMap->getWidth();
	portion.h = guiMap->getHeight();
	this->completeSurface = surfaceFactory->createSurface(portion, BLUE);
	this->completeSurface->setTransparentColor(BLUE);

	util::LinkedList<GUIObject>::Iterator it = guiMap->getGUIObjects().iterator();
	while (it.hasNext()) {
		GUIObject* current = it.next();
		Surface* surface = current->asSurface();
		completeSurface->applySurface(surface);
	}

	delete guiMap;
}

MapLayer::~MapLayer() { }

}
